<include target="_header.html" />
<!--%import("css/default.css")-->
	
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
	// <![CDATA[
	var flag;
	var data = new Array();
	var sumPrice = new Object();
	var minimumPrice = new Object();
	
	var payment = new Array();
		
	function amount(num, i){
		if($('#numBox_'+num).val() < 1){
			if (i == 1)	
				$('#numBox_'+num).val(parseInt($('#numBox_'+num).val())+i);		
		}
		else{
			$('#numBox_'+num).val(parseInt($('#numBox_'+num).val())+i);
		}
	}	
	 
	function check_form(e){
		var address_value = $("#inputAddress").attr('value');

		if(address_value && (address_value.indexOf("율전")>-1 || address_value.indexOf("천천")>-1 || address_value.indexOf("율천")>-1 || address_value.indexOf("성균")>-1 || address_value.indexOf("성대")>-1 )) {		
			if(confirm("해당 주문내용이 확실합니까?")) {
				$('.contentvar').val($('.contentView').html());
				delCookie();
				$(document).find('.order_detail').each(function() {
					if($(this).val() == "추가요구사항을 적어주세요.") $(this).val("null");
				});
				return procFilter(e, window.insert);
			}
			else return false;
		}
		else {
			alert("주문 가능 지역은 성균관대학교 자연과학 캠퍼스 주변으로 제한됩니다.");
			return false;
		}
	}
	
	    // 추가요구사항 글자수제한 - 병웅
	    function limitCharacters(e, limit){
	        // 잆력 값 저장
	        var text = $(e).val();
	        // 입력값 길이 저장
	        var textlength = text.length;
	        if(textlength > limit){
	                alert("글내용을 "+limit+"자 이상 쓸수 없습니다!");
	                // 제한 글자 길이만큼 값 재 저장
	                $(e).val(text.substr(0,limit));
	                return false;
	        }
		}
	
	function fncFocus(obj)
	{
	    if($(obj).attr("focus_var")=="1")
	    {
	        obj.value = '';
	        $(obj).attr("focus_var","0");
	    }
	}

	
	var geocoder;
	var map;
	var marker;
	var firstClick=0;
	
	(function($){
	    $(function(){
			$(document).ready(function() {
						
				var logged_address_0 = '{$logged_info->address[0]}';
				var logged_address_1 = '{$logged_info->address[1]}';
							
				var for_splite_char_index = logged_address_0.indexOf("(");
	
				logged_address_0 = logged_address_0.substring(0,for_splite_char_index)
				var logged_address = logged_address_0.concat(logged_address_1);
				$('.logged_address').append(logged_address);
	
				$('.address_text').empty();
				$('.address_text').append(logged_address);
	
	
			    geocoder = new google.maps.Geocoder();
			    infowindow = new google.maps.InfoWindow();
			    
				var latlng = new google.maps.LatLng(37.29355, 126.974208);
				var myOptions = {
					zoom: 16,
					center: latlng,
					mapTypeId: google.maps.MapTypeId.ROADMAP,
					scrollwheel: false
				};
				map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
							
				if(logged_address) {
				    geocoder.geocode( { 'address': logged_address}, function(results, status) {
				      if (status == google.maps.GeocoderStatus.OK) {
				        map.setCenter(results[0].geometry.location);
				        marker = new google.maps.Marker({
				            map: map, 
				            position: results[0].geometry.location
				        });
				        
						$('.text').each(function(j) {
							if ($(this).attr('name')=='extra_vars11') {
								$(this).attr({value:results[0].geometry.location.lat()});
							}
							if ($(this).attr('name')=='extra_vars12') {
								$(this).attr({value:results[0].geometry.location.lng()});
							}
			
							if ($(this).attr('name')=='extra_vars13') {
							// 20110515 신청
								$(this).attr({value:logged_address});
							}
						});
				      } else {
				        alert("Geocode was not successful for the following reason: " + status);
				      }
				    });
				}
				
				google.maps.event.addListener(map, 'click', function(event) {
					if(firstClick==0) {
						$('#map_canvas').css('width','670px');
						$('#map_canvas').css('height','350px');
						
						google.maps.event.trigger(map, 'resize');
						
						map.setCenter(new google.maps.LatLng(37.29355, 126.974208));
						
						firstClick=1;
					}
					else {
						map.setCenter(event.latLng);
	
						$('.text').each(function(j) {
							if ($(this).attr('name')=='extra_vars11') {
								$(this).attr({value:event.latLng.lat()});
							}
							if ($(this).attr('name')=='extra_vars12') {
								$(this).attr({value:event.latLng.lng()});
							}
						});
		
						var latlng1 = new google.maps.LatLng(event.latLng.lat(), event.latLng.lng());
		
					    if (geocoder) {
							geocoder.geocode( { 'latLng': latlng1}, function(results, status) {
								if (status == google.maps.GeocoderStatus.OK) {
							        if (results[0]) {
										map.setZoom16;
		      							marker.setMap();
		      
										marker = new google.maps.Marker({
							            	position: latlng1, 
											map: map
										});
		          
				          				$('.text').each(function(j) {
											if ($(this).attr('name')=='extra_vars13') {
												$(this).attr({value:results[0].formatted_address});
											}
										});
										
										$('.address_text').empty();
										$('.address_text').append(results[0].formatted_address);
										$('.contentvar').val($('.contentView').html());
									} else {
										alert("No results found");
							        }
		      					} else {
							        alert("Geocoder failed due to: " + status);
								}
							});
						}
					}
				});
			});
	    });
	})(jQuery);
	// ]]>
</script>

<div style="width:750px; float:left;">
<form action="./" method="post" onsubmit="return check_form(this);" class="board_write" name="board_write" id="form1" style="width:750px;">
	<input type="hidden" name="mid" value="{$mid}" />
	<input type="hidden" name="content" value="{$oDocument->getContentText()}" />
	<input type="hidden" name="document_srl" value="{$document_srl}" />
<!-- 20110428. 리팩토링중 정리
	<input type="hidden" name="extra_vars5" value="Y" />
-->
	<input type="hidden" name="allow_comment" value="Y" />
	<input type="hidden" name="allow_trackback" value="Y" />
	
	<div class="write_header">
		<input cond="$oDocument->getTitleText()" type="text" name="title" class="iText" title="{$lang->title}" value="{htmlspecialchars($oDocument->getTitleText())}" />
		<input cond="!$oDocument->getTitleText()" type="hidden" name="title" class="iText" title="{$lang->title}" value="{$logged_info->user_name}님의 주문 입니다."/>
	</div>
	
	{@
		$product_data = Context::get('product_data');
		$product_data2 = explode("&&", $product_data);
		$count_product = count($product_data2)-1;
		$sum_price=0;
		$tmp;
		$span = array();
		$span_tmp=1;
		$span_sum = array();
		$span_sum_tmp=0;
		$strData="";
		$strSpan="";
		$strSpan_sum="";
		$count_store = 0;
		$delivery="";
	
	}
	
	<!--@for($i=0; $i< $count_product; $i++)-->
		{@ 
			$product[$i] = explode("|", $product_data2[$i]);
		}
	<!--@end-->
	<br />
	
	<!-- // 비교를 통해 같은것들끼리 묶는다 -->
	<!--@for($i=0; $i< $count_product-1; $i++)-->
		<!--@for($j=$i+1; $j< $count_product; $j++)-->
			<!--@if($product[$i][1] == $product[$j][1])-->
				{@
					$tmp = $product[$i+1];
					$product[$i+1] = $product[$j];
					$product[$j] = $tmp;
				}
			<!--@endif-->
		<!--@end-->
	<!--@end-->

	<!--@for($i=0; $i<$count_product;$i++)-->
		<!--@if($product[$i][1] == $product[$i+1][1])-->
			{@
				$span_tmp++;
				$span_sum_tmp += $product[$i][4];
			}
		<!--@else-->
			{@
				$count_store++;
				$span_sum_tmp += $product[$i][4];
				array_push($span_sum,$span_sum_tmp);
				array_push($span,$span_tmp);
				$span_tmp=1;
				$span_sum_tmp=0;
				$delivery.="1|"
			}	
		<!--@endif-->
		{@
			$product[$i][6] = Context::get('payment_'.$product[$i][1]);
			
			$strData .= $product[$i][0]."|".$product[$i][1]."|".$product[$i][2]."|".$product[$i][3]."|".$product[$i][4]."|".$product[$i][5]."|".$product[$i][6]."&&";
		}

	<!--@end-->
	
	<!--@for($i=0; $i<count($span);$i++)-->
		{@
			$strSpan_sum .= $span_sum[$i]."|";
			$strSpan .= $span[$i]."|";
		}
	<!--@end-->


	<div>
		<!-- 20110428. 리팩토링중 제거
        <input type="hidden" name="recipient" class="iText" value="{$recipient}111" />
        <input type="hidden" name="callback" class="iText" value="{$logged_info->cellphone[0]}{$logged_info->cellphone[1]}{$logged_info->cellphone[2]}"/>
        <input type="hidden" name="notification" class="iText" value="{$notification}" />
        <input type="hidden" name="restaurant_email" class="iText" value="{$restaurant_email}" />
        -->
    </div>

	<div>
		<input type="hidden" name="extra_vars1" class="text" value="{$strData}"/>
	    <input type="hidden" name="extra_vars2" class="text" value="{$strSpan}" />
	    <input type="hidden" name="extra_vars3" class="text" value="{$delivery}" />
	    <input type="hidden" name="extra_vars4" class="text" value="{$logged_info->cellphone[0]}{$logged_info->cellphone[1]}{$logged_info->cellphone[2]}" />
	    <input type="hidden" name="extra_vars6" id="mobile_content" class="text" value="" />
	    <input type="hidden" name="extra_vars8" class="text" value="{$strSpan_sum}" />
	    <input type="hidden" name="extra_vars10" class="text" value="{$notification}" />
	    {@
		    $no_head = $logged_info->member_srl%100;
			$today=mktime();
			$no_middle = date('m', $today);
			$no_bottom = date('s', $today);
			$real_no = $no_head.$no_middle.$no_bottom;
	    }
	    <input type="hidden" name="extra_vars14" class="text" value="{$real_no}" />
	</div>

	<div class="contentView">
		<div class="order_confirm_alert"></div>
		{@$counter=0;}
		
		<!--@for($i=0; $i<$count_store; $i++)-->
			<div class="divWrapContent">
				<div style="border-bottom:1px solid #e1e1e1; height:25px; background-color:#fafafa; ">
					<div style="color:#fff; background-color:#3bbeef; width:100%; margin-left:20px; padding:5px 10px; margin-right:50px; width:auto; float:left;">
						{$product[$counter][1]}
					</div>
					<div style = "padding:5px; float:right; margin-right:10px; margin-top:2px;">
						주문번호 : {$real_no}
					</div>
				</div>
	    		<table class="tableContent">
					<tr>
						<th width="150">&nbsp;{$span[$kk]}</th>
						<th>상품명</th>
						<th width="60">수량</th>
						<th width="100">가격</th>
						<th width="100">합계</th>
					</tr>
				<!--@for($j=0; $j < $span[$i]; $j++)-->
					<tr>
						<td>
							{@  $oFileModel = &getModel('file');
							    $file_list = $oFileModel->getFiles($product[$counter][0]);
								$file = (Object)$file_list[0];									
							}
							<img class="thumb" src="{$file->uploaded_filename}" width=100 height=90>
						</td>
						<td>{$product[$counter][2]}</td>
						<td>{$product[$counter][3]}</td>
						<td>{number_format($product[$counter][4]/$product[$counter][3])} 원</td>
						<td>{number_format($product[$counter][4])} 원</td>
							{@
								$sum_price += $product[$counter][4];
								$counter++;
							}	
					</tr>
				<!--@end-->
				</table>
				<table class="tablePayment" align="center">
					<tr style="background:#fcfcfc">
						<td style="text-align:left; padding-left:30px;"><img src="images/point_rect.png"> 주문시 요구사항</td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>							
					</tr>
					<tr>
						<td colspan="5">
							<textarea class="order_detail" onfocus='javascript:fncFocus(this);' name="order_detail[]" style="width:95%;height:18px;font-size:9pt;overflow:hidden;border:1px solid #e1e1e1;wrap=hard;resize:none;" focus_var="1">추가요구사항을 적어주세요.</textarea>
						</td>
					</tr>
					<tr style="background:#fcfcfc">
						<td style="text-align:left; padding-left:30px;"><img src="images/point_rect.png"> 결제방식</td>
						<td cond="$product[$counter-1][6] == 'cash'"><img src="images/cash.png"> 현금</td>
						<td cond="$product[$counter-1][6] == 'card'"><img src="images/card.png"> 카드</td>
						<td><img src="images/point_rect.png"> 합계</td>
						<td>{number_format($span_sum[$i])} 원</td>
					</tr>
				</table>
				
				<script>
					//2011.04.23 안병웅이 철저한 리팩토링 예정
					payment['{$product[$counter-1][1]}'] = "{$product[$counter-1][6]}";
					if (payment['{$product[$counter-1][1]}'] == "cash") payment['{$product[$counter-1][1]}'] = "현금";
					else if (payment['{$product[$counter-1][1]}'] == "card") payment['{$product[$counter-1][1]}'] = "카드";
					//alert('{$product[$counter-1][1]}');
				</script>
			</div>
		<!--@end-->
		<table class="tableAddressSelect">
			<tr style="background:#fcfcfc">
				<td style="text-align:left; padding-left:30px;border-bottom: 1px solid #e1e1e1;">
					<img src="images/point_rect.png"> 배송 정보 입력
				</td>
			</tr>
			<tr>
				<td style="padding-left:36px;">
					{@$recent_address = explode("|",$logged_info->recentaddress);}
					<select id="selectAddress">
					<option value="{$logged_info->address[0].$logged_info->address[1]}">최근배송지 목록</option>
					<!--@for($i=0;$i<5;$i++)-->
						<!--@if($recent_address[$i])-->
							<option value="{$recent_address[$i]}">→{$recent_address[$i]}</option>
						<!--@endif-->
					<!--@end-->
					<option value="{$logged_info->address[0].$logged_info->address[1]}">가입시 주소</option>
					<option value="-1">직접입력하기</option>
					</select>
					<input type="text" name="extra_vars13" id="inputAddress" class="text" size="65" value=""/>
				</td>
			</tr>
		</table>
		<div id="#divAddress" width=750>
			<input type="hidden" name="extra_vars11" class="text" value=""/>
		    <input type="hidden" name="extra_vars12" class="text" value=""/>
			<div id="map_canvas" style="width:670px; height:350px; margin:10px auto; border:1px solid #e1e1e1;"></div>
		</div>
		<table class="tablePaymentTotal">
			<tr>
				<td><img src="images/point_rect.png"> 최종결제금액</td><td><font color="#006ec3"><a class="sum_price"></a></font></td>
			</tr>
		</table>
	</div>
	
    <input type="hidden" name="extra_vars9" class="text" value="{$sum_price}" />
	<input type="hidden" name="content" class="contentvar" value=""/>
	    
	<div style="text-align:center; margin-bottom:20px;">
		<input type="image" src="images/button_confirm_big.png" />
	</div>
</form>
</div>

<div id="divCart" style="margin-top:16px; margin-right:0;">
	<div class="divOrderTitle">
    </div>
	<div class="divOrderToolbar">
       	<div class="divOrderToolbarLeft">
        	<img id="toggleSwitchCalory" src="images/chart_curve.png" class="icon16px" alt="칼로리보기" />
            <img id="toggleSwitchPrice" src="images/won.png" class="icon16px" alt="개별가격보기" />
        </div>
    	<div class="divOrderToolbarRight">
        </div>
    </div>
	<div class="divOrder">
		<b>{$logged_info->user_name}님의 주문서</b>
		<hr />
		
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td width="110">상품명</td>
				<td width="55" align="right">
	            	<div class="divPriceViews">
	                	가격
	                </div>
	            </td>
				<td width="35" align="right">수량</td>
			</tr>
		</table>
		<hr />
		
		<div class="orderListWrap">
            <div class="divOrderList">
            </div>
		</div>
        <hr />
	</div>
	<div class="divOrderStatus">
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="100%">
				<b style="width:50px;float:left;">합계</b><span style="width:150px;float:left;text-align:right;"><b><span id="spanPriceAmount">0</span>원</span></b><br /><hr>
                <div class="divCaloryViews">
					<b style="width:50px;float:left;">총열량</b><span style="width:150px;float:left;text-align:right;"><b><span id="spanCalorieAmount">0</span>KCal</span></b>
                    <br />
                </div>
			</td>
		</tr>
		</table>
	</div>
</div>

<script type="text/javascript">
	(function($){
	    $(function(){
			$('.sum_price').append('<b>{number_format($sum_price)} 원</b>');
			$('.contentvar').val($('.contentView').html());
			$('#mobile_content').val($('#divCart').html());
			//$('.product_name a').remove();
			$('#selectAddress').change(function(){
				$("#selectAddress option:selected").each(function () {
                	if ($(this).val() == -1){
                		$("#inputAddress").val('');
                	}
                	else {
	                	$("#inputAddress").val($(this).val());
                	}
              });
			})
	    });
	    
    $('.order_detail').keyup(function(e){
	    limitCharacters(this, 30);
    })
	    
	})(jQuery);
</script>

<!-- 20110515. 주문마법사 -->
{@
	$extra_words_data = Context::get('extra_words_data');
	$address_value_data = Context::get('address_value_data');
}

<script type="text/javascript">
	$(document).ready(function() {
	
		var extra_words_data = '{$extra_words_data}';
		
		var extra_words_data2 = extra_words_data.split("&&");
	
		$('.order_detail').each(
			function(n) {
				if(extra_words_data2[n]!="") {
					$(this).empty();
					$(this).append(extra_words_data2[n]);
				}
			}
		);
		
		var address_value_data = '{$address_value_data}';
		//alert($('#inputAddress').attr('value'));
		//alert(address_value_data);
		if(address_value_data=!"") {
			$('#inputAddress').val(address_value_data);
		}
		//alert($('#inputAddress').attr('value'));		
	});
</script>

<include target="_footer.html" />
